package com.itheima.day6;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo2 {
    public static void main(String[] args) {
        //创建一个集合
        HashMap<Student,String> hs = new HashMap<>();
        //创建对象
        Student s1 = new Student("小王",21);
        Student s2 = new Student("小李",20);
        Student s3 = new Student("小三",18);
        //将键和值添加  值为祖籍
        hs.put(s1,"北京");
        hs.put(s2,"南京");
        hs.put(s3,"东京");
        //遍历素集合 来获得键
   /*    // Set<Student> s = hs.keySet();
        for (Student stu : s) {
            String s4 = hs.get(stu);
            System.out.println(stu+s4);*/
        /*hs.forEach((Student st ,String  s )->{
            System.out.println(st+s);
        });*/
        //调用方法获得键队值

        Set<Map.Entry<Student, String>> entries = hs.entrySet();
        for (Map.Entry<Student, String> en : entries) {
            en.getKey();
            en.getValue();
            System.out.println();
        }
    }

    }
